<?php

namespace app\admin\controller;

use app\admin\model\AdminUser;
use app\common\controller\AdminBaseController;
use app\common\model\tang\Cost;
use app\common\model\tang\RepairMaterial;
use app\common\model\tang\Close as CloseModel;
use app\common\model\tang\TaskList;
use think\facade\Db;
use app\common\model\tang\Merchant;
use app\common\model\tang\Task;

class TaskMerchant extends AdminBaseController
{
    protected function initialize()
    {
        parent::initialize(); // TODO: Change the autogenerated stub
        $this->model = new CloseModel();
    }

    //首页
    public function index()
    {
        if (IS_AJAX) {
            return $this->model->getTaskData($this->param, 'id desc',[]);
        }
        //任务列表
        $task = (new Task())->select()->toArray();
        $this->assign('task',$task);
        return $this->fetch();
    }
    /**
     * 查看对应任务未上报的商户
     */
    public function noReport(){

        $param = $this->param;
        $info = TaskList::where('id',$param['id'])->find();
        $merchantSun=[];
        if(!empty($info['no_report'])){
            foreach (explode(',',$info['no_report']) as $k=>$v){
                $merchantSun[] = Merchant::field('id,name')->where('id',$v)->find()->toArray();
            }
        }
//        $merchantSun = Merchant::where('task_id','like','%'.$info['type'].'%')->field('id,name')->select();
//        $reportInfo = CloseModel::where('type',$info['type'])->whereBetweenTime('create_time', $info['start_time'], $info['end_time'])->field('id,merchant_id')->select();
//        foreach ($merchantSun as $k=>$v){
//            foreach ($reportInfo as $kk=>$vv){
//                if($v['id']==$vv['merchant_id']){
//                    unset($merchantSun[$k]);
//                }
//            }
//        }
        $this->assign('list',$merchantSun);
        return $this->fetch();
    }
}